package nju.software.tagmanager.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: raychou
 * @date: 2023-11-27 12:41
 * @description:
 */
public class ParserUtil {
    /**
     * @param str 要求str格式为"[,,,]"
     * @return
     */
    public static List<Integer> parseStringToIntegerList(String str) {
        String[] split = str
                .replace("[", "")
                .replace("]", "")
                .split(",");
        ArrayList<Integer> list = new ArrayList<>();
        for (String s : split) {
            if (!StringUtils.isBlank(s))
                list.add(Integer.valueOf(s.trim()));
        }
        return list;
    }

    /**
     * @param str 要求str格式为"[,,,]"
     * @return
     */
    public static List<String> parseStringToStringList(String str) {
        String[] split = str.replace("[", "").replace("]", "").split(",");

        ArrayList<String> list = new ArrayList<>();
        for (String s : split) {
            if (!StringUtils.isBlank(s))
                list.add(s.trim());
        }
        return list;
    }
}
